package org.jash.learnmvp.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class StoreUtils {
    private SharedPreferences sp;
    private static StoreUtils instance;

    private StoreUtils(SharedPreferences sp) {
        this.sp = sp;
    }
    public static void init(Context context) {
        instance = new StoreUtils(context.getSharedPreferences("store", Context.MODE_PRIVATE));
    }
    public static StoreUtils getInstance() {
        if (instance == null){
            throw new RuntimeException("使用StoreUtils前要初始化");
        }
        return instance;
    }
    public void put(String key, String value) {
        sp.edit().putString(key, value).commit();
    }
    public String getString(String key, String defValue) {
        return sp.getString(key, defValue);
    }
}
